/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package grafica;

import static java.lang.Math.*;
import javax.swing.JFrame;
import javax.swing.JPanel;

/**
 *
 * @author Rossy
 */
public class GraficasTest extends JFrame{
    public GraficasTest(){
        Graficas migrafica=new Graficas(Graficas.LINEAL, "Mi Grafica");
        double [] x = rango(1,360,0.5);
        double[] y = f(x);
        migrafica.agregarGrafica("sin(x)", x, y);
        JPanel panel=migrafica.obtienePanel();
        this.setSize(600,600);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.add(panel);
        this.setVisible(true);
    }    
    public double [] rango (double xi,double xn,double d){
        int n=(int) ((xn-xi)/d);
        double [] r = new double[n];
        for (int i=0;i<n;i++){
            r[i]=xi+d*i;
        } 
        return r;
    }
    public double [] f(double []x){
        int n=x.length;
        double [] y = new double[n];
        for(int i=0;i<n;i++){
            double radianes=x[i]*PI/180;
            y[i] = sin(radianes);
        }
        return y;
    }
    
    public static void main (String[] args){
        new GraficasTest();
    }
}
